<?php 
require_once('db_abstract_model.php');

class User extends DBAbstractModel {

 protected $id;  
 public $username;
 private $password; 
 public $name; 
 public $surname; 
 public $country;
 public $city;
 public $address;
 public $phone;
 public $email; 
 public $birthdate;
 
 function __construct() { 
	$this->db_name = 'saveUrPet'; 
 } 
 
 public function get($username='') { 
	if($username != ''): 
		$this->query = "SELECT Id,Username,Password,Name,Surname,Country,City,Address,Phone,email,birthdate 
			FROM usuarios 
			WHERE Username = '$username'"; 
		$this->get_results_from_query(); 
	endif; 
	
	if(count($this->rows) == 1): 
		foreach ($this->rows[0] as $propiedad=>$valor): 
			$this->$propiedad = $valor; 
		endforeach; 
	endif; 
} 

 public function set($user_data=array()) { 
	if(array_key_exists('username', $user_data)): 
		$this->get($user_data['username']); 
		if($user_data['username'] != $this->username): 
			foreach ($user_data as $campo=>$valor): 
				$campo = $valor; 
			endforeach; 
			$this->query = "INSERT INTO user 
					(Username,Password,Name,Surname,Country,City,Address,Phone,email,birthdate) VALUES 
					('$username','$password','$name','$surname','$country', '$city', '$address', '$phone',$email','$birthdate')"; 
			$this->execute_single_query(); 
		endif; 
	endif; 
 } 
 
 public function edit($user_data=array()) { 
	foreach ($user_data as $campo=>$valor): 
		$campo = $valor; 
	endforeach; 
	$this->query = "UPDATE user 
			SET name='$name', 
				surname='$surname', 
				clave='$clave' 
			WHERE email = '$email'"; 
	$this->execute_single_query(); 
 } 
 
 public function delete($user_email='') { 
	$this->query = "DELETE FROM usuarios 
			WHERE email = '$user_email'"; 
	$this->execute_single_query(); 
 } 
 
 function __destruct() { 
 unset($this); 
 } 
} 
?>